package tests;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import roborally.EnergyAmount;
import roborally.EnergyUnit;

/**
 * @version	3.0
 * @author 	Lies Tambeur 	r0264469	2Bcwsbbh
 * @author	Eline Vanrykel	r0264543	2Bcwselt
 * 
 */
public class EnergyAmountTest {
	
	private EnergyAmount thousand;
	
	/**
	 * Set up a mutable test fixture.
	 * 
	 * @post   The variable robot33Orient0Energy20000 references a new
	 *         robot with with position (3,3), energy 20000 and orientation 0.
	 * @post   The variable robot82Orient3Energy8000 references a new
	 *         robot with  position (8,2), energy 8000 and orientation 3.
	 */
	@Before
	public void setUp() throws Exception {
		thousand = new EnergyAmount(1000,EnergyUnit.WATTSECONDS);
	}
	
	@Test
	public final void equals_TrueCase_DifferentUnitskJWs(){
		EnergyAmount e1 = new EnergyAmount(1,EnergyUnit.KILOJOULE);
		EnergyAmount e2 = new EnergyAmount(1000,EnergyUnit.WATTSECONDS);
		assertTrue(e1.equals(e2));
		assertTrue(e2.equals(e1));
	}
	
	@Test
	public final void equals_TrueCase_DifferentUnitsJWs(){
		EnergyAmount e1 = new EnergyAmount(5,EnergyUnit.JOULE);
		EnergyAmount e2 = new EnergyAmount(5,EnergyUnit.WATTSECONDS);
		assertTrue(e1.equals(e2));
		assertTrue(e2.equals(e1));
	}
	
	@Test
	public final void equals_TrueCase_DifferentUnitsJkJ(){
		EnergyAmount e1 = new EnergyAmount(5000,EnergyUnit.JOULE);
		EnergyAmount e2 = new EnergyAmount(5,EnergyUnit.KILOJOULE);
		assertTrue(e1.equals(e2));
		assertTrue(e2.equals(e1));
	}
	
	@Test
	public final void equals_TrueCase_SameUnitskJ(){
		EnergyAmount e1 = new EnergyAmount(3,EnergyUnit.KILOJOULE);
		EnergyAmount e2 = new EnergyAmount(3,EnergyUnit.KILOJOULE);
		assertTrue(e1.equals(e2));
	}
	
	@Test
	public final void equals_TrueCase_SameUnitsWs(){
		EnergyAmount e1 = new EnergyAmount(3,EnergyUnit.WATTSECONDS);
		EnergyAmount e2 = new EnergyAmount(3,EnergyUnit.WATTSECONDS);
		assertTrue(e1.equals(e2));
	}
	
	@Test
	public final void equals_TrueCase_SameUnitsJ(){
		EnergyAmount e1 = new EnergyAmount(3,EnergyUnit.JOULE);
		EnergyAmount e2 = new EnergyAmount(3,EnergyUnit.JOULE);
		assertTrue(e1.equals(e2));
	}
	
	@Test
	public final void addAndReturn_DifferentUnits(){
		EnergyAmount e1 = new EnergyAmount(5,EnergyUnit.KILOJOULE);
		assertEquals(thousand.addAndReturn(e1),new EnergyAmount(6000,EnergyUnit.JOULE));
	}
	
	@Test
	public final void addAndReturn_SameUnits(){
		EnergyAmount e1 = new EnergyAmount(5,EnergyUnit.WATTSECONDS);
		assertEquals(thousand.addAndReturn(e1),new EnergyAmount(1005,EnergyUnit.JOULE));
	}
	
	@Test
	public final void subtractAndReturn_DifferentUnits(){
		EnergyAmount e1 = new EnergyAmount(0.5,EnergyUnit.KILOJOULE);
		assertEquals(thousand.subtractAndReturn(e1),new EnergyAmount(500,EnergyUnit.JOULE));
	}
	
	@Test
	public final void subtractAndReturn_SameUnits(){
		EnergyAmount e1 = new EnergyAmount(5,EnergyUnit.WATTSECONDS);
		assertEquals(thousand.subtractAndReturn(e1),new EnergyAmount(995,EnergyUnit.JOULE));
	}
	
	@Test
	public final void subtractAndReturn_ToNegative(){
		try{
			EnergyAmount e1 = new EnergyAmount(5,EnergyUnit.KILOJOULE);
			thousand.subtractAndReturn(e1);
		}
		catch(AssertionError e){
			assertTrue(true);
			assertEquals(new EnergyAmount(1000,EnergyUnit.WATTSECONDS),thousand);
		}
	}
	
	@Test
	public final void multiplyAndReturn(){
		assertEquals(new EnergyAmount(3000,EnergyUnit.WATTSECONDS),thousand.multiplyAndReturn(3));
	} 
	
	@Test
	public final void multiplyAndReturn2(){
		assertEquals(new EnergyAmount(800,EnergyUnit.WATTSECONDS),thousand.multiplyAndReturn(0.8));
	} 
	
	@Test
	public final void divideAndReturn(){
		assertEquals(new EnergyAmount(500,EnergyUnit.WATTSECONDS),thousand.divideAndReturn(2));
	}
	
	@Test
	public final void isSmallerThan_TrueCase_SameUnits(){
		assertTrue(thousand.isSmallerThan(new EnergyAmount(2000,EnergyUnit.WATTSECONDS)));
	}
	
	@Test
	public final void isSmallerThan_TrueCase_DifferentUnits(){
		assertTrue(thousand.isSmallerThan(new EnergyAmount(2,EnergyUnit.KILOJOULE)));
	}
	
	@Test
	public final void isSmallerThan_FalseCase_SameUnits(){
		assertFalse(thousand.isSmallerThan(new EnergyAmount()));
	}
	
	@Test
	public final void isSmallerThan_FalseCase_DifferentUnitsEqualValues(){
		assertFalse(thousand.isSmallerThan(new EnergyAmount(1,EnergyUnit.KILOJOULE)));
	}
	
	@Test
	public final void isSmallerThan_FalseCase_DifferentUnits(){
		assertFalse(thousand.isSmallerThan(new EnergyAmount(500,EnergyUnit.JOULE)));
	}
	
}
